<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>
<html xmlns='http://www.w3.org/1999/xhtml'>
<head>
<title>maint/utils/sync-transifex/functions</title>
<meta name='robots' content='noindex,nofollow' />
<meta name='generator' content='GLOBAL-6.5.7' />
<meta http-equiv='Content-Style-Type' content='text/css' />
<link rel='stylesheet' type='text/css' href='../style.css' />
</head>
<body>
<!-- beginning of fixed guide -->
<div id='guide'><ul>
<li><a href='#TOP'><img class='icon' src='../icons/first.png' alt='[^]' /></a></li>
<li><a href='#BOTTOM'><img class='icon' src='../icons/last.png' alt='[v]' /></a></li>
<li><a href='#TOP'><img class='icon' src='../icons/top.png' alt='[top]' /></a></li>
<li><a href='#BOTTOM'><img class='icon' src='../icons/bottom.png' alt='[bottom]' /></a></li>
<li><a href='../mains.html'><img class='icon' src='../icons/index.png' alt='[index]' /></a></li>
<li><a href='../help.html'><img class='icon' src='../icons/help.png' alt='[help]' /></a></li>
<li class='standout'><span><a href='../files/maint.html'>maint</a>/<a href='../files/maint--utils.html'>utils</a>/<a href='../files/maint--utils--sync-transifex.html'>sync-transifex</a>/functions</span></li>
</ul></div>
<!-- end of fixed guide -->
<a id='TOP' name='TOP'></a><h2 class='header'><a href='../mains.html'>root</a>/<a href='../files/maint.html'>maint</a>/<a href='../files/maint--utils.html'>utils</a>/<a href='../files/maint--utils--sync-transifex.html'>sync-transifex</a>/functions</h2>
<em class='comment'>/* <img class='icon' src='../icons/n_left.png' alt='[previous]' /><img class='icon' src='../icons/n_right.png' alt='[next]' /><img class='icon' src='../icons/n_first.png' alt='[first]' /><img class='icon' src='../icons/n_last.png' alt='[last]' /><img class='icon' src='../icons/n_top.png' alt='[top]' /><a href='#BOTTOM'><img class='icon' src='../icons/bottom.png' alt='[bottom]' /></a><a href='../mains.html'><img class='icon' src='../icons/index.png' alt='[index]' /></a><a href='../help.html'><img class='icon' src='../icons/help.png' alt='[help]' /></a>&nbsp;<input type='text' readonly onfocus='this.select();' value='+1 maint/utils/sync-transifex/functions'  /> */</em>
<hr />
<pre>
<a id='L1' name='L1'></a>#!/bin/bash
<a id='L2' name='L2'></a> 
<a id='L3' name='L3'></a># Midnight Commander - common functions for playing with translations.
<a id='L4' name='L4'></a>#
<a id='L5' name='L5'></a># Copyright (C) 2013
<a id='L6' name='L6'></a># The Free Software Foundation, Inc.
<a id='L7' name='L7'></a>#
<a id='L8' name='L8'></a># Written by:
<a id='L9' name='L9'></a>#  Slava Zanko &lt;slavazanko@gmail.com&gt;, 2013
<a id='L10' name='L10'></a>#
<a id='L11' name='L11'></a># This file is part of the Midnight Commander.
<a id='L12' name='L12'></a>#
<a id='L13' name='L13'></a># The Midnight Commander is free software: you can redistribute it
<a id='L14' name='L14'></a># and/or modify it under the terms of the GNU General Public License as
<a id='L15' name='L15'></a># published by the Free Software Foundation, either version 3 of the License,
<a id='L16' name='L16'></a># or (at your option) any later version.
<a id='L17' name='L17'></a>#
<a id='L18' name='L18'></a># The Midnight Commander is distributed in the hope that it will be useful,
<a id='L19' name='L19'></a># but WITHOUT ANY WARRANTY; without even the implied warranty of
<a id='L20' name='L20'></a># MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
<a id='L21' name='L21'></a># GNU General Public License for more details.
<a id='L22' name='L22'></a>#
<a id='L23' name='L23'></a># You should have received a copy of the GNU General Public License
<a id='L24' name='L24'></a># along with this program.  If not, see &lt;http://www.gnu.org/licenses/&gt;.
<a id='L25' name='L25'></a> 
<a id='L26' name='L26'></a>#*** include section (source functions, for example) *******************
<a id='L27' name='L27'></a> 
<a id='L28' name='L28'></a>#*** file scope functions **********************************************
<a id='L29' name='L29'></a># ----------------------------------------------------------------------
<a id='L30' name='L30'></a> 
<a id='L31' name='L31'></a>## Returns name of working directory.
<a id='L32' name='L32'></a>##
<a id='L33' name='L33'></a>## @param sync_file_name file name which will be sync'ed with Transifex
<a id='L34' name='L34'></a>## @return name of working directory
<a id='L35' name='L35'></a> 
<a id='L36' name='L36'></a>getSyncDirName() {
<a id='L37' name='L37'></a>    sync_file_name=$1; shift
<a id='L38' name='L38'></a>    echo "${SYNC_TX_CURRENT_DIR}/var.d/${sync_file_name}"
<a id='L39' name='L39'></a>}
<a id='L40' name='L40'></a> 
<a id='L41' name='L41'></a># ----------------------------------------------------------------------
<a id='L42' name='L42'></a> 
<a id='L43' name='L43'></a>## Returns config file name as full path.
<a id='L44' name='L44'></a>##
<a id='L45' name='L45'></a>## @param sync_file_name   file name which will be sync'ed with Transifex
<a id='L46' name='L46'></a>## @param config_file_name config file name
<a id='L47' name='L47'></a>## @return config file name
<a id='L48' name='L48'></a> 
<a id='L49' name='L49'></a>getConfigFile() {
<a id='L50' name='L50'></a>    sync_file_name=$1; shift
<a id='L51' name='L51'></a>    config_file_name=$1; shift
<a id='L52' name='L52'></a> 
<a id='L53' name='L53'></a>    echo "${MC_SOURCE_ROOT_DIR}/maint/utils/sync-transifex/config.d/${sync_file_name}/${config_file_name}"
<a id='L54' name='L54'></a>}
<a id='L55' name='L55'></a> 
<a id='L56' name='L56'></a># ----------------------------------------------------------------------
<a id='L57' name='L57'></a> 
<a id='L58' name='L58'></a> 
<a id='L59' name='L59'></a>## Returns name of working directory. Init the directory, if needed.
<a id='L60' name='L60'></a>##
<a id='L61' name='L61'></a>## @param sync_file_name file name which will be sync'ed with Transifex
<a id='L62' name='L62'></a>## @return name of working directory
<a id='L63' name='L63'></a> 
<a id='L64' name='L64'></a>initSyncDirIfNeeded() {
<a id='L65' name='L65'></a>    sync_file_name=$1; shift
<a id='L66' name='L66'></a> 
<a id='L67' name='L67'></a>    sync_dir_name=$(getSyncDirName "${sync_file_name}")
<a id='L68' name='L68'></a> 
<a id='L69' name='L69'></a>    [ ! -e  "${sync_dir_name}" ] &amp;&amp; mkdir -p "${sync_dir_name}/.tx"
<a id='L70' name='L70'></a>    cp \
<a id='L71' name='L71'></a>        "$(getConfigFile ${sync_file_name} 'tx.config')" \
<a id='L72' name='L72'></a>        "${sync_dir_name}/.tx/config"
<a id='L73' name='L73'></a> 
<a id='L74' name='L74'></a>    echo "${sync_dir_name}"
<a id='L75' name='L75'></a>}
<a id='L76' name='L76'></a> 
<a id='L77' name='L77'></a># ----------------------------------------------------------------------
<a id='L78' name='L78'></a> 
<a id='L79' name='L79'></a>## Convert file from plain text to POT-file format.
<a id='L80' name='L80'></a>##
<a id='L81' name='L81'></a>## @param source_file      path to plain text file
<a id='L82' name='L82'></a>## @param destination_file path to po-file
<a id='L83' name='L83'></a> 
<a id='L84' name='L84'></a>convertFromTextToPo() {
<a id='L85' name='L85'></a>    source_file=$1; shift
<a id='L86' name='L86'></a>    destination_file=$1; shift
<a id='L87' name='L87'></a> 
<a id='L88' name='L88'></a>    po4a-gettextize -f text -m "${source_file}" -p "${destination_file}"
<a id='L89' name='L89'></a>}
<a id='L90' name='L90'></a> 
<a id='L91' name='L91'></a># ----------------------------------------------------------------------
<a id='L92' name='L92'></a> 
<a id='L93' name='L93'></a>## Send POT-file to Transifex.
<a id='L94' name='L94'></a>##
<a id='L95' name='L95'></a>## @param tx_work_dir working directory where placed the POT file and
<a id='L96' name='L96'></a>##                    a config-file for tx utility
<a id='L97' name='L97'></a> 
<a id='L98' name='L98'></a>sendSourceToTransifex() {
<a id='L99' name='L99'></a>    tx_work_dir=$1; shift
<a id='L100' name='L100'></a> 
<a id='L101' name='L101'></a>    tx -r "${tx_work_dir}" push -s
<a id='L102' name='L102'></a>}
<a id='L103' name='L103'></a> 
<a id='L104' name='L104'></a># ----------------------------------------------------------------------
<a id='L105' name='L105'></a> 
<a id='L106' name='L106'></a>## Reveive translations from Transifex.
<a id='L107' name='L107'></a>##
<a id='L108' name='L108'></a>## @param tx_work_dir working directory where placed the POT file and
<a id='L109' name='L109'></a>##                    a config-file for tx utility
<a id='L110' name='L110'></a> 
<a id='L111' name='L111'></a>receiveTranslationsFromTransifex() {
<a id='L112' name='L112'></a>    tx_work_dir=$1; shift
<a id='L113' name='L113'></a> 
<a id='L114' name='L114'></a>    pushd "${tx_work_dir}" &gt;/dev/null
<a id='L115' name='L115'></a>    tx pull --all --force
<a id='L116' name='L116'></a>    popd &gt;/dev/null
<a id='L117' name='L117'></a>}
<a id='L118' name='L118'></a> 
<a id='L119' name='L119'></a># ----------------------------------------------------------------------
<a id='L120' name='L120'></a> 
<a id='L121' name='L121'></a>## Create po4a.cfg file.
<a id='L122' name='L122'></a>##
<a id='L123' name='L123'></a>## @param sync_file_name file name which will be sync'ed with Transifex
<a id='L124' name='L124'></a> 
<a id='L125' name='L125'></a>createPo4A() {
<a id='L126' name='L126'></a>    sync_file_name=$1; shift
<a id='L127' name='L127'></a> 
<a id='L128' name='L128'></a>    sync_dir_name=$(getSyncDirName "${sync_file_name}")
<a id='L129' name='L129'></a>    [ ! -e  "${sync_dir_name}" ] &amp;&amp; mkdir -p "${sync_dir_name}"
<a id='L130' name='L130'></a> 
<a id='L131' name='L131'></a>    pushd $sync_dir_name &gt;/dev/null
<a id='L132' name='L132'></a>    translations=$(ls *.po| sed -e 's/.po//g'| tr '\n' ' ')
<a id='L133' name='L133'></a>    popd &gt;/dev/null
<a id='L134' name='L134'></a>    sed -e 's!@srcdir@!'"${MC_SOURCE_ROOT_DIR}"'!g' \
<a id='L135' name='L135'></a>        -e 's!@translations@!'"${translations}"'!g' \
<a id='L136' name='L136'></a>        "$(getConfigFile ${sync_file_name} 'po4a.cfg')" \
<a id='L137' name='L137'></a>        &gt; "${sync_dir_name}/po4a.cfg"
<a id='L138' name='L138'></a>}
<a id='L139' name='L139'></a> 
<a id='L140' name='L140'></a># ----------------------------------------------------------------------
<a id='L141' name='L141'></a> 
<a id='L142' name='L142'></a>## Create po4a.cfg file.
<a id='L143' name='L143'></a>##
<a id='L144' name='L144'></a>## @param sync_dir_name   working directory where placed translations
<a id='L145' name='L145'></a>## @param sync_file_name file name which will be sync'ed with Transifex
<a id='L146' name='L146'></a> 
<a id='L147' name='L147'></a>convertFromPoToText() {
<a id='L148' name='L148'></a>    sync_dir_name=$1; shift
<a id='L149' name='L149'></a>    sync_file_name=$1; shift
<a id='L150' name='L150'></a>    pushd "${SYNC_TX_CURRENT_DIR}"  &gt;/dev/null
<a id='L151' name='L151'></a>    po4a -k 0 -q \
<a id='L152' name='L152'></a>        -M UTF-8 -L UTF-8 \
<a id='L153' name='L153'></a>        --variable docfile="${sync_file_name}" \
<a id='L154' name='L154'></a>        "${sync_dir_name}/po4a.cfg"
<a id='L155' name='L155'></a>    popd  &gt;/dev/null
<a id='L156' name='L156'></a>}
<a id='L157' name='L157'></a> 
<a id='L158' name='L158'></a># ----------------------------------------------------------------------
<a id='L159' name='L159'></a>#*** main code *********************************************************
<a id='L160' name='L160'></a> 
<a id='L161' name='L161'></a>SYNC_TX_CURRENT_DIR=${SYNC_TX_CURRENT_DIR:-${MC_SOURCE_ROOT_DIR}/maint/utils/sync-transifex}
</pre>
<hr />
<a id='BOTTOM' name='BOTTOM'></a>
<em class='comment'>/* <img class='icon' src='../icons/n_left.png' alt='[previous]' /><img class='icon' src='../icons/n_right.png' alt='[next]' /><img class='icon' src='../icons/n_first.png' alt='[first]' /><img class='icon' src='../icons/n_last.png' alt='[last]' /><a href='#TOP'><img class='icon' src='../icons/top.png' alt='[top]' /></a><img class='icon' src='../icons/n_bottom.png' alt='[bottom]' /><a href='../mains.html'><img class='icon' src='../icons/index.png' alt='[index]' /></a><a href='../help.html'><img class='icon' src='../icons/help.png' alt='[help]' /></a>&nbsp;<input type='text' readonly onfocus='this.select();' value='+161 maint/utils/sync-transifex/functions'  /> */</em>
</body>
</html>
